package com.yanqu.road.server.cmd.activity.flowerstudy;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FlowerStudyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.flowerstudy.CrossFlowerStudyMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = CrossProtocol.C_FLOWER_STUDY_GET_CROSS_USER_DATA, desc = "获取跨服考试数据")
public class CrossFlowerGetUserDataCmd extends CrossCommand {

    private int activityId;

    private String language= "";

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FlowerStudyProto.FlowerStudyUserCrossExamDataReq req = FlowerStudyProto.FlowerStudyUserCrossExamDataReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        if (req.hasLanguage()){
            language = req.getLanguage();
        }

        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        FlowerStudyProto.getUserCrossDataToServerResp.Builder crossUserDataMsg = CrossFlowerStudyMgr.getCrossUserDataMsg(activityId, packet.getPlayerId(), (int) serverId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_FLOWER_STUDY_GET_CROSS_EXAM_DATA_RESULT_FROM_CROSS,crossUserDataMsg);
        MessageHelper.sendPacket(serverId,packet.getPlayerId(),pbMsg);
        if (!StringUtils.isNullOrEmpty(language)){
            CrossFlowerStudyMgr.updateLanguage(activityId,language);
        }
    }

    @Override
    public void sendData() {

    }
}
